package org.dromara.admin.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.admin.domain.bo.UserRemarkBo;
import org.dromara.admin.domain.vo.UserRemarkVo;
import org.dromara.admin.service.IUserRemarkService;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 后台端用户备注
 *
 * @author Lion Li
 * @date 2025-11-03
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/admin/userRemark")
public class AdminUserRemarkController extends BaseController {

    private final IUserRemarkService userRemarkService;

    /**
     * 查询用户备注列表
     */
//    @SaCheckPermission("system:userRemark:list")
    @GetMapping("/list")
    public TableDataInfo<UserRemarkVo> list(UserRemarkBo bo, PageQuery pageQuery) {
        return userRemarkService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出用户备注列表
     */
//    @SaCheckPermission("system:userRemark:export")
    @Log(title = "用户备注", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(UserRemarkBo bo, HttpServletResponse response) {
        List<UserRemarkVo> list = userRemarkService.queryList(bo);
        ExcelUtil.exportExcel(list, "用户备注", UserRemarkVo.class, response);
    }

    /**
     * 获取用户备注详细信息
     *
     * @param id 主键
     */
//    @SaCheckPermission("system:userRemark:query")
    @GetMapping("/{id}")
    public R<UserRemarkVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(userRemarkService.queryById(id));
    }

    /**
     * 新增用户备注
     */
//    @SaCheckPermission("system:userRemark:add")
    @Log(title = "用户备注", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody UserRemarkBo bo) {
        return toAjax(userRemarkService.insertByBo(bo));
    }

    /**
     * 修改用户备注
     */
//    @SaCheckPermission("system:userRemark:edit")
    @Log(title = "用户备注", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody UserRemarkBo bo) {
        return toAjax(userRemarkService.updateByBo(bo));
    }

    /**
     * 删除用户备注
     *
     * @param ids 主键串
     */
//    @SaCheckPermission("system:userRemark:remove")
    @Log(title = "用户备注", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(userRemarkService.deleteWithValidByIds(List.of(ids), true));
    }
}
